<?php

    header('content-type:text/html;charset=utf-8') ;
    header("Access-Control-Allow-Origin:*");

    
<<<<<<< HEAD


    $host = 'b-k5hmuwuw4s0vsb.bch.rds.gz.baidubce.com:3306';
    $name = 'b_k5hmuwuw4s0vsb';
    $pwd = 'czm061002';
    $dbname = 'b_k5hmuwuw4s0vsb';
    $conn = mysqli_connect("b-k5hmuwuw4s0vsb.bch.rds.gz.baidubce.com","b_k5hmuwuw4s0vsb","czm061002","b_k5hmuwuw4s0vsb") ;
=======
    $host = 'localhost';
    $name = 'root';
    $pwd = 'root';
    $dbname = '123';
    $conn = mysqli_connect($host , $name , $pwd , $dbname);
>>>>>>> c2a0b16d374b2dadbf60483b2ca7e378d937a164

    if(!$conn) {
        die('数据库连接失败');
    }

    $uname = $_POST['phone'];
    $obj = [] ;
    


    $sql = "SELECT * from cart , goods_list where goods_list.goods_id = cart.goods_id and cart.phone   = '$uname'";
    // 默认只会转第一条数据
    $res = mysqli_query($conn , $sql) ;

    $list = [] ;

    while($data = mysqli_fetch_array($res)) {
        $temp = [] ;
        $temp['id'] = $data['goods_id'] ;
        $temp['name'] = $data['goods_name'] ;
        $temp['title'] = $data['goods_title'] ;
        $temp['des'] = $data['goods_des'] ;
        $temp['img'] = $data['goods_img'] ;
        $temp['price'] = $data['goods_price'] ;
        $temp['type'] = $data['goods_type'] ;
        $temp['sale'] = $data['goods_sale'] ;
        $temp['num'] = $data['cart_num'] ;
        array_push($list , $temp) ;
    }

    if($list) {
        $obj['status'] = true ;
        $obj['msg'] = '数据请求成功';
        $obj['data'] = $list ;
    } else {
        $obj['status'] = false ;
        $obj['msg'] = '购物车空空如也';
        $obj['data'] = $list ;
    }

    echo(json_encode($obj , JSON_UNESCAPED_UNICODE));